import Toast from 'tdesign-miniprogram/toast';
Component({
	externalClasses: ['wr-sold-out', 'wr-class'],

	options: {
		multipleSlots: true,
		listdeta: [],
		vinde: '',
		shippingSpacestr: ''
	},

	properties: {
		details: {
			type: Array,
			value: [],
			observer(num) {
				console.log(num);
				this.setData({
					listdeta: num
				})
			},
		},
		vin: {
			type: String,
			value: [],
			observer(num) {
				console.log(num);
				this.setData({
					vinde: num
				})
			},
		},
		listdata: {
			type: Array,
			value: [],
			observer(num) {
				console.log(num);
				this.setData({
					listdt: num
				})
			},
		},
		soldout: {
			// 商品是否下架
			type: Boolean,
			value: false,
		},
		jumpArray: {
			type: Array,
			value: [],
		},
		isStock: {
			type: Boolean,
			value: true,
		}, // 是否有库存
		isSlotButton: {
			type: Boolean,
			value: false,
		}, // 是否开启按钮插槽
		shopCartNum: {
			type: Number, // 购物车气泡数量
		},
		buttonType: {
			type: Number,
			value: 0,
		},
		minDiscountPrice: {
			type: String,
			value: '',
		},
		minSalePrice: {
			type: String,
			value: '',
		},
		shippingSpace: {
			type: String,
			value: '',
			observer(num) {
				console.log(num);
				this.setData({
					shippingSpacestr: num
				})
			},
		}
	},

	data: {
		fillPrice: false,
		listdt: []
	},

	methods: {
		toAddCart() {
			const {
				isStock
			} = this.properties;
			if (!isStock) return;
			let login = wx.getStorageSync('login')
			if (login != '' && login.data.code != 500) {
				this.triggerEvent('toAddCart');
			} else {
				Toast({
					context: this,
					selector: '#t-toast',
					message: '请先登录，在选购商品',
					duration: 2000,
				});
			}

		},
		toNav(e) {
			const {
				url
			} = e.currentTarget.dataset;
			return this.triggerEvent('toNav', {
				e,
				url,
			});
		},
		toBuyNow(e) {
			console.log(this.data.shippingSpacestr);
			// console.log(e);
			// console.log(this.data.listdeta);
			// const {
			// 	isStock
			// } = this.properties;
			// if (!isStock) return;
			// this.triggerEvent('toBuyNow', e);
			console.log(e);
			console.log(this.data.listdeta);
			if (e.currentTarget.dataset.item[0].inventory > 0) {
				let login = wx.getStorageSync('login')
				if (login != '' && login.data.code != 500 && login.data != undefined) {
					const listr = JSON.stringify(this.data.listdeta);
					console.log(listr);
					// console.log(productNumber);
					wx.navigateTo({
						url: `/packageA/pages/Shopbuying/index?data=${listr}&vin=${this.data.vinde}&danjiage=2&shippingSpace=${this.data.shippingSpacestr}`,
					})
				} else {
					Toast({
						context: this,
						selector: '#t-toast',
						message: '请先登录，在选购商品',
						duration: 2000,
					});
				}
			} else {
				Toast({
					context: this,
					selector: '#t-toast',
					message: '当前商品已售罄，请选择其他商品',
					duration: 2000,
				});
			}
		},
	},


});